package com.sskj.wallet.ui.activity;


import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ImgUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.CopyUtil;
import com.sskj.lib.util.QRCodeUtil;
import com.sskj.wallet.R;
import com.sskj.wallet.R2;
import com.sskj.wallet.bean.CoinAssetBean;
import com.sskj.wallet.presenter.CashActivityPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;

@Route(path = RConfig.WALLET_CASH)//收款
public class CashActivity extends BaseActivity<CashActivityPresenter> {
    @Autowired
    CoinAssetBean data;
    @BindView(R2.id.ivQRCode)
    ImageView ivQRCode;
    @BindView(R2.id.tvAddress)
    TextView tvAddress;
    @BindView(R2.id.btCopy)
    Button btCopy;

    @Override
    protected int getLayoutId() {
        return R.layout.wallet_activity_cash;
    }

    @Override
    public CashActivityPresenter getPresenter() {
        return new CashActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(App.INSTANCE.getString(R.string.wallet_cashActivity1_j));
        ARouter.getInstance().inject(this);

        tvAddress.setText(data.getAddress());
        QRCodeUtil.createImage(data.getAddress(), 400, new QRCodeUtil.OnEncodeQRCodeCallback() {
            @Override
            public void onAnalyzeSuccess(Bitmap bitmap) {
                ivQRCode.setImageBitmap(bitmap);
            }

            @Override
            public void onAnalyzeFailed() {

            }
        });
        ClickUtil.click(btCopy, () -> {
            CopyUtil.copy(data.getAddress());
        });
        ivQRCode.setOnClickListener(v -> {
            ImgUtil.saveImageToGallery(this,ivQRCode);
        });
    }


}
